package cn.jiyun.controller;
import cn.jiyun.pojo.Constactor;
import cn.jiyun.pojo.Developer;
import cn.jiyun.pojo.Constactor;
import cn.jiyun.result.PageResult;
import cn.jiyun.result.QueryPageBean;
import cn.jiyun.result.Result;
import cn.jiyun.service.ConstactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("constactor")
public class ConstactorController {

    @Autowired
    private ConstactorService constactorService;

    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        List<Map> list=constactorService.findPage(queryPageBean);
        /*分页查询*/
        PageResult result = new PageResult();
        result.setRows(list);
        /*查询记录数*/
        long i=constactorService.jilu();
        result.setTotal(i);
        return result;
    }

    @RequestMapping("add")
    public Result add(@RequestBody Constactor constactor){
        int i=constactorService.add(constactor);
        if (i>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"error");
        }
    }

    @RequestMapping("edit")
    public Result edit(@RequestBody Constactor constactor){
        int i=constactorService.edit(constactor);
        if (i>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"error");
        }
    }

    @RequestMapping("delete")
    public Result delete(Integer cid){
        try {
            constactorService.delete(cid);
            return new Result(true,"success");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"error");
        }
    }

    @RequestMapping("findById")
    public List<Constactor> findById(Integer cid){
        return constactorService.findById(cid);
    }
}
